// 日期处理
export const formatTime = (date: Date) => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return (
    [year, month, day].map(formatNumber).join('/') +
    ' ' +
    [hour, minute, second].map(formatNumber).join(':')
  )
}

const formatNumber = (n: number) => {
  const s = n.toString()
  return s[1] ? s : '0' + s
}

// 获取当前日期的前30天
export const getNext30DaysWithWeekdays = () => {
  const today = new Date()
  const datesWithWeekdays = []
  for (let i = 0; i <= 30; i++) {
    const date = new Date(today.getFullYear(), today.getMonth(), today.getDate() + i)
    const weekday = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][date.getDay()]
    const formattedDate = `${date.getFullYear()}-${('0' + (date.getMonth() + 1)).slice(-2)}-${(
      '0' + date.getDate()
    ).slice(-2)}(${weekday})`
    datesWithWeekdays.push(formattedDate)
  }
  // 如果是17点，则只返回17点后的日期
  if (today.getHours() == 17) {
    return datesWithWeekdays.slice(1, datesWithWeekdays.length)
  } else {
    return datesWithWeekdays
  }
}

//获取当前时间的整点到18点
export const getNextFullHourUntil17 = (selectDate: string) => {
  // 处理选择日期的时间
  const selectDay = selectDate.split('-')[2]
  const now = new Date()
  const currentHour = now.getHours()
  const currentDay = now.getDate()
  const timeList = []
  for (let i = 8; i <= 18; i++) {
    timeList.push(i + ':00')
  }

  // 如果返回的日期是当天的日期，则返回当前点的时间
  if (selectDay === currentDay.toString()) {
    const index = timeList.findIndex((item) => item === currentHour + ':00')
    return timeList.slice(index + 1, timeList.length)
  } else {
    return timeList
  }
}

// 获取10天的天数
export const getTenDays = () => {
  const daysArr = []
  for (let i = 1; i <= 10; i++) {
    daysArr.push(i + '*天')
  }
  return daysArr
}
